"""借款申请审核"""
from selenium.webdriver.common.by import By
from base.page_base import BasePage


class LoanApplicationReview(BasePage):
    """借款申请审核"""
    # 部分变量
    username = "13612342289"

    # 元素定位
    __loan_management_btn = By.LINK_TEXT, '借款管理'  # 借款管理按钮
    __first_review_management_btn = By.XPATH, '//span[text()="初审管理"]'  #初审管理按钮
    __first_review_mark = By.XPATH, '//a[contains(normalize-space(.), "初审标")]' #初审标
    __cd_iframe_list_page = By.ID, 'iframe_box' # 切换为列表页面iframe
    __username_search = By.CSS_SELECTOR, '[name="userName"]' # 用户名搜索框
    __search_btn = By.CSS_SELECTOR, '[value="搜索"]' # 搜索按钮
    __list_first_record = By.CSS_SELECTOR, '[ng-repeat="list in tableB"]:nth-of-type(10)' # 列表页面第一个记录,用于识别搜索前页面已消失

    __loan_application_record = By.XPATH, f'//span[text()={username}]' # 指定的申请记录
    __review_btn = By.XPATH, '//span[text()="审核"]' # 审核按钮
    __cd_iframe_review_page = By.CSS_SELECTOR, '[class="xubox_iframe"]' # 切换为审核页面iframe
    __review_status = By.XPATH, '//span[text()="通过"]' # 审核状态
    __review_label = By.CSS_SELECTOR, '[name="marker_type"]' # 审核标签
    __review_note = By.CSS_SELECTOR, 'textarea' # 审核备注
    __review_verifycode = By.CSS_SELECTOR, '[name="valicode"]' # 验证码
    __save_btn = By.CSS_SELECTOR, '[value="保存"]' # 保存按钮
    __assert_success_text = By.CSS_SELECTOR, '[class="xubox_msg xubox_text"]' # 断言审核成功文本


    def click_loan_management(self):
        """点击借款管理按钮"""
        self.base_click(self.__loan_management_btn)

    def click_first_review_management(self):
        """点击初审管理按钮"""
        self.base_click(self.__first_review_management_btn)

    def click_first_review_mark(self):
        """点击初审标"""
        self.base_click(self.__first_review_mark)

    def switch_to_cd_iframe_list_page(self):
        """切换为列表页面iframe"""
        self.base_switch_frame(self.__cd_iframe_list_page)

    def input_username_search(self):
        """输入用户名搜索框"""
        self.base_input(self.__username_search, self.username)

    def click_search_btn(self):
        """点击搜索按钮"""
        self.base_click(self.__search_btn)

    def click_loan_application_record(self):
        """点击指定的申请记录"""
        self.fd_wait_element_disappear(self.__list_first_record)
        self.base_click(self.__loan_application_record)

    def click_review_btn(self):
        """点击审核按钮"""
        self.base_click(self.__review_btn)

    def switch_to_cd_iframe_review_page(self):
        """切换为审核页面iframe"""
        self.base_switch_frame(self.__cd_iframe_review_page)

    def input_review_status(self):
        """点击选择审核状态"""
        self.base_click(self.__review_status)

    def input_review_label(self, review_label='测试007'):
        """输入审核标签"""
        self.base_input(self.__review_label, review_label)

    def input_review_note(self, review_note='测试007'):
        """输入审核备注"""
        self.base_input(self.__review_note, review_note)

    def input_review_verifycode(self, review_verifycode='8888'):
        """输入验证码"""
        self.base_input(self.__review_verifycode, review_verifycode)

    def click_save_btn(self):
        """点击保存按钮"""
        self.base_click(self.__save_btn)

    def assert_success_text(self):
        """断言审核成功文本"""
        return self.base_get_text(self.__assert_success_text)

    def loan_application_review_process(self):
        """借款申请审核流程"""
        self.click_loan_management() # 点击借款管理按钮
        self.click_first_review_management() # 点击初审管理按钮
        self.click_first_review_mark() # 点击初审标
        self.switch_to_cd_iframe_list_page() # 切换为列表页面iframe
        self.input_username_search() # 输入用户名搜索框
        self.click_search_btn() # 点击搜索按钮
        self.click_loan_application_record() # 点击指定的申请记录
        self.click_review_btn() # 点击审核按钮
        self.switch_to_cd_iframe_review_page() # 切换为审核页面iframe
        self.input_review_status() # 点击选择审核状态
        self.input_review_label() # 输入审核标签
        self.input_review_note() # 输入审核备注
        self.input_review_verifycode() # 输入验证码
        self.click_save_btn() # 点击保存按钮





